package coba.mailing.query;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import coba.mailing.model.Guia;

public class FindGuiaBySolicitudId {

	public static List<Guia> find(Connection con, Long solicitudId) throws SQLException {

		String sql = " select * from COBA_Guia g inner join COBA_SolicitudGuia sg on g.guiaId = sg.guiaId "
				+ " and sg.solicitudId = ? ";

		PreparedStatement stmt = con.prepareStatement(sql);

		stmt.setLong(1, solicitudId);

		ResultSet rs = stmt.executeQuery();

		List<Guia> list = new LinkedList<Guia>();

		while (rs.next()) {
			Guia obj = new Guia(
					rs.getLong("g.guiaId"),
					rs.getString("g.apellido"),
					rs.getString("g.nombre"),
					rs.getString("g.telefono"));

			list.add(obj);
		}

		rs.close();
		stmt.close();

		return list;

	}

}
